<!DOCTYPE html>
<html class="x-admin-sm">

<head>
<meta charset="UTF-8">
<title>新增专家</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./lib/layui/layui.js"
	charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>

<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-row">
			<form class="layui-form">
				<div class="layui-form-item">
					<label for="professorname" class="layui-form-label"> <span
						class="x-red">*</span>专家姓名
					</label>
					<div class="layui-input-inline">
						<input type="text" id="professorname" name="professorname" lay-verify="professorname"
							required="required" autocomplete="off" class="layui-input">
					</div>
					<div class="layui-form-mid layui-word-aux">
						<span class="x-red">*</span>
					</div>
				</div>
				<div class="layui-form-item">
					<label for="gender" class="layui-form-label">
						性别
					</label>
					<div class="layui-input-inline" style="margin-top: 8px;">
						<input type="checkbox" id="gender" name="gender" lay-skin = "switch" lay-text = "男|女" checked="checked" lay-filter = "gender" class="layui-input" />
					</div>
				</div>
				<div class="layui-form-item">
					<label for="birthday" class="layui-form-label">
							出生年月
					</label>
					<div class="layui-input-inline">
						<input  id="birthday" name="birthday"
							lay-verify="birthday" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="identitynumber" class="layui-form-label">
							身份证号
					</label>
					<div class="layui-input-inline">
						<input type="text" id="identitynumber" name="identitynumber"
							   lay-verify="identityNumber" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="workstatus" class="layui-form-label">
							工作状态
					</label>
					<div class="layui-input-inline">
						<select name="workstatus" id="workstatus">

						</select>

					</div>
				</div>
				<div class="layui-form-item">
					<label for="institution" class="layui-form-label">
							毕业院校
					</label>
					<div class="layui-input-inline">
						<input type="text" id="institution" name="institution"
							   lay-verify="institution" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="education" class="layui-form-label">
							学历
					</label>
					<div class="layui-input-inline">
						<select name="education" id="education">

						</select>

					</div>
				</div>
				<div class="layui-form-item">
					<label for="major" class="layui-form-label">
							专业
					</label>
					<div class="layui-input-inline">
						<input type="text" id="major" name="major"
							   lay-verify="major" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="employcompany" class="layui-form-label">
							工作单位
					</label>
					<div class="layui-input-inline">
						<input type="text" id="employcompany" name="employcompany"
							   lay-verify="employCompany" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="administrative" class="layui-form-label">
							行政职务
					</label>
					<div class="layui-input-inline">
						<select id="administrative" name="administrative">

						</select>

					</div>
				</div>
				<div class="layui-form-item">
					<label for="technicalpost" class="layui-form-label">
							技术职称
					</label>
					<div class="layui-input-inline">
						<select id="technicalpost" name="technicalpost">

						</select>

					</div>
				</div>
				<div class="layui-form-item">
					<label for="telephone" class="layui-form-label">
						固定电话
					</label>
					<div class="layui-input-inline">
						<input type="telephone" id="telephone" name="phone"
							lay-verify="telephone" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="mobliephone" class="layui-form-label">
						手机号
					</label>
					<div class="layui-input-inline">
						<input type="text" id="mobliephone" name="mobliephone"
							   lay-verify="mobliePhone" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="address" class="layui-form-label">
						所在地址
					</label>
					<div class="layui-input-inline">
						<input type="text" id="address" name="address" placeholder="可以通过下方的选择或者直接输入"
							   lay-verify="address" autocomplete="off" class="layui-input">
					</div>
					<!-- start-->
					<div class="layui-form-item x-city" id="end">
						<!--<label class="layui-form-label">所在地址</label>-->
						<div class="layui-input-inline">
							<select name="province" id="province" lay-filter="province">
								<option value="">请选择省</option>
							</select>
						</div>
						<div class="layui-input-inline">
							<select name="city" id="city" lay-filter="city">
								<option value="">请选择市</option>
							</select>
						</div>
						<div class="layui-input-inline">
							<select name="area" id="area" lay-filter="area">
								<option value="">请选择县/区</option>
							</select>
						</div>
					</div>

					<!-- end -->
				</div>
				<div class="layui-form-item">
					<label for="projectcategory" class="layui-form-label">
						评审项目类型
					</label>
					<div class="layui-input-inline">
						<input type="text" id="projectcategory" name="projectcategory"
							lay-verify="projectCategory" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="workdate" class="layui-form-label"> <span
						class="x-red"></span>工作年限
					</label>
					<div class="layui-input-inline">
						<input type="number" min="0" id="workdate" name="workdate"
							lay-verify="workDate" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label  class="layui-form-label"></label>
					<label  class="layui-form-label"></label>
					<button class="layui-btn" lay-filter="add" lay-submit="">增加</button>
				</div>
			</form>
		</div>
	</div>

	<script type="text/javascript" src="./js/xcity.js"></script>
	<script>


		layui.use([ 'form', 'laydate','layer', 'jquery','code'],
			function() {
				var $ = layui.jquery;
				 form = layui.form;
                var layer = layui.layer;
                var laydate=layui.laydate;

				//
                //传默认值
                $('#end').xcity('安徽','合肥市','包河区');

				//
				laydate.render({
					elem : '#birthday' //指定元素
					,trigger: 'click'
				});
				var $role=$("#workstatus");
				$.get("js/param.json",function(data){
					$.each(data.workStatus,function(i,d){
						$role.append(new Option(d,d));
					});
					form.render();//重绘表单
				});
                var $xueli=$("#education");
                $.get("js/param.json",function(data){
                    $.each(data.education,function(i,d){
                        $xueli.append(new Option(d,d));
                    });
                    form.render('select');//重绘表单
                });
                var administrative=$("#administrative");
                $.get("js/param.json",function(data){
                    $.each(data.administrative,function(i,d){
                        administrative.append(new Option(d,d));
                    });
                    form.render('select');//重绘表单
                });
                var technicalPost=$("#technicalpost");
                $.get("js/param.json",function(data){
                    $.each(data.technicalPost,function(i,d){
                        technicalPost.append(new Option(d,d));
                    });
                    form.render('select');//重绘表单
                });
				//
                // form.on('select(province)',function (data) {
                //     initAddr();
                //     return true;
                // });

                //$("#city").click(initAddr);
                //$("#city").click(initAddr);
                // form.on('select(city)',function (data) {
                //     initAddr();
                // });
                // form.on('select(area)',function (data) {
                //     initAddr();
                // });
				// form.on("select(city)",function (data) {
				// 	alert(data.value+">>>>>>>>>>>>>>>");
                // });
                function initAddr(){

                        var p=$("#province").val();
                        var c=$("#city").val();
                        var area=$("#area").val();
                        $("#address").val(p+" "+c+" "+area);
                        form.render();
				}
				//自定义验证规则
				form.verify({

                    professorName : function(value) {
						if (value.length < 2||value.length >12) {
							return '用户名必须是2-12个字符';
						}
					},
                    identityNumber : [ /\d{17}(\d|X)$/, '身份证必须是18位' ]

				});
	
				//监听提交
				form.on('submit(add)',
					function(data) {
                        if(data.field.gender == "on") {
                            data.field.gender = "男";
                        } else {
                            data.field.gender = "女";
                        }
                       //initAddr();
                        var p=$("#province").val();
                        var c=$("#city").val();
                        var area=$("#area").val();
                        data.field.address=p+" "+c+" "+area;
						 alert(JSON.stringify(data.field));
						//发异步，把数据提交给
						$.post("professorAdd",data.field,function(r){
							if(r.code==0){
								parent.layer.alert("增加成功", {
									icon : 6
								},function(index,item){
									xadmin.close(); 
									// 可以对父窗口进行刷新 
									xadmin.father_reload();
								});
								
								
								
							}else{
								parent.layer.alert("增加失败，请核对", {
									icon : 1
								});
							}
						});
						 
						return false;
					});
	
			});
	</script>

</body>

</html>    